package stream;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public class StreamEnd {
    public static void main(String[] args) {
        Student.getStudents().stream()
                .forEach(System.out::println);
        System.out.println("====================");
        boolean bool = Student.getStudents().stream()
                .allMatch(stu -> stu.getName().equals("lucy"));
        System.out.println(bool);
        System.out.println("====================");
        Optional<Student> first = Student.getStudents().stream()
                .findFirst();
        first.ifPresent(System.out::println);
        System.out.println("====================");
        Optional<Integer> sum = Student.getStudents().stream()
                .map(Student::getAge)
                .reduce(Integer::sum);
        sum.ifPresent(System.out::println);
        System.out.println("===================");
        long count = Student.getStudents().stream()
                .count();
        System.out.println(count);
        System.out.println("====================");
        Student.getStudents().stream()
                .max(Comparator.comparingInt(Student::getAge))
                .ifPresent(System.out::println);
        System.out.println("=======================");
        List<Student> list = Student.getStudents().stream()
                .toList();
        System.out.println(list);
        System.out.println("========================");
        Map<String, Student> map = Student.getStudents().stream()
                .collect(Collectors.toMap(Student::getName, student -> student));
        System.out.println(map);
        System.out.println("========================");
        Double collect = Student.getStudents().stream()
                .collect(Collectors.averagingDouble(Student::getAge));
        System.out.println(collect);
        System.out.println("=========================");
        Map<String, List<Student>> genMap = Student.getStudents().stream()
                .collect(Collectors.groupingBy(Student::getGen));
        System.out.println(genMap);
        System.out.println("============================");
        String stringName = Student.getStudents().stream()
                .map(Student::getName)
                .collect(Collectors.joining(","));
        System.out.println(stringName);
    }
}
